import {reqCategoryList} from '@/api'
const state = {
  categoryList:[]
}
const mutations = {
  RECEIVE_CATEGORYLIST(state,categoryList){
    state.categoryList = categoryList
  }
}
const actions = {
  //异步请求获取数据，提交给mutations，修改state的对应数据
  // getCategoryList({commit}){
  //   reqCategoryList().then((response) => {
  //     commit('RECEIVE_CATEGORYLIST',response.data)
  //   })
  // }
  // async 和 await 使用同步代码达到解决异步效果

  async getCategoryList({commit}){
    const result = await reqCategoryList()
    if(result.code === 200){
      commit('RECEIVE_CATEGORYLIST',result.data)
    }
  }
}



const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}